﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLQTPM_Nhom03
{
    public partial class Form_TimKiem : Form
    {
        public Form parent = null;
        private bool arrow_down = true;

        public Form_TimKiem()
        {
            InitializeComponent();
        }

        private void LB_CapNhatDuLieu_MouseEnter(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu_MouseEnter(sender, e);
        }

        private void LB_CapNhatDuLieu_MouseLeave(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu_MouseLeave(sender, e);
        }

        private void Panel_CapNhatDuLieu_MouseEnter(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton2_hover;
        }

        private void Panel_CapNhatDuLieu_MouseLeave(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton2;
        }

        private void PB_CapNhatDuLieu_MouseEnter(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu_MouseEnter(sender, e);
        }

        private void PB_CapNhatDuLieu_MouseLeave(object sender, EventArgs e)
        {
            Panel_CapNhatDuLieu_MouseLeave(sender, e);
        }

        private void Panel_TimKiemNangCao_MouseEnter(object sender, EventArgs e)
        {
            Panel_TimKiemNangCao.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.Panel_TimKiemNangCao_hover;
        }

        private void Panel_TimKiemNangCao_MouseLeave(object sender, EventArgs e)
        {
            Panel_TimKiemNangCao.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.Panel_TimKiemNangCao;
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            Panel_TimKiemNangCao_MouseEnter(sender, e);
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            Panel_TimKiemNangCao_MouseLeave(sender, e);
        }

        private void Form_TimKiem_Load(object sender, EventArgs e)
        {
            //TB_Input.AutoSize = false;
            //TB_Input.Height = 28;
            //DGV_KetQua.Font = new System.Drawing.Font("Calibri", 9, FontStyle.Bold);

            DGV_KetQua.Rows.Add("Ngân hàng", "Đông Á", "16", "Bến Nghé", "Bến Nghé", "37.7771", "-122.44", "Chi nhánh ngân hàng Đông Á");
            DGV_KetQua.Rows.Add("Bệnh viện", "Nhi Đồng", "20", "Bến Nghé", "Bến Nghé", "38.7771", "-122.44", "");
            DGV_KetQua.Rows.Add("Siêu thị", "Big C", "101", "Bến Nghé", "Bến Nghé", "39.7771", "-122.44", "");
            DGV_KetQua.Rows.Add("Nhà hàng", "KFC", "200", "Bến Nghé", "Bến Nghé", "40.7771", "-122.44", "Nhà hàng bán gà rán");

            CB_DichVu.Items.Add("Tất cả các dịch vụ");
            CB_DichVu.Items.Add("ATM");
            CB_DichVu.Items.Add("Cây xăng");
            CB_DichVu.Items.Add("Siêu thị");
            CB_DichVu.Items.Add("Bưu điện");
            CB_DichVu.Items.Add("Rạp chiếu phim");
            CB_DichVu.Items.Add("Ngân hàng");
            CB_DichVu.Items.Add("Nhà hàng");
            CB_DichVu.Items.Add("Bệnh viện");

            //for (int y = 0; y < DGV_KetQua.Rows[0].Cells.Count; y++)
            //{
            //    DGV_KetQua.Rows[0].Cells[y].Style.BackColor =
            //    System.Drawing.Color.Transparent;
            //}
        }

        private void Panel_TimKiem_MouseEnter(object sender, EventArgs e)
        {
            Panel_TimKiem.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton5;
        }

        private void Panel_TimKiem_MouseLeave(object sender, EventArgs e)
        {
            Panel_TimKiem.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton4;
        }

        private void PB_TimKiem_MouseEnter(object sender, EventArgs e)
        {
            Panel_TimKiem_MouseEnter(sender, e);
        }

        private void PB_TimKiem_MouseLeave(object sender, EventArgs e)
        {
            Panel_TimKiem_MouseLeave(sender, e);
        }

        private void Form_TimKiem_FormClosing(object sender, FormClosingEventArgs e)
        {
            //this.parent.Location = this.Location;
            //this.parent.Visible = true;
            this.parent.Dispose();
        }

        private void Panel_TimKiem_Click(object sender, EventArgs e)
        {
            this.parent.Location = this.Location;
            this.Dispose();
            this.parent.Visible = true;
        }

        private void Button_Tim_MouseEnter(object sender, EventArgs e)
        {
            Panel_Tim.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6_hover;
        }

        private void Button_Tim_MouseLeave(object sender, EventArgs e)
        {
            Panel_Tim.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6;
        }

        private void Button_QuayLai_MouseEnter(object sender, EventArgs e)
        {
            Panel_QuayLai.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6_hover;
        }

        private void Button_QuayLai_MouseLeave(object sender, EventArgs e)
        {
            Panel_QuayLai.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6;
        }

        private void Button_InKetQua_MouseEnter(object sender, EventArgs e)
        {
            Panel_InKetQua.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6_hover;
        }

        private void Button_InKetQua_MouseLeave(object sender, EventArgs e)
        {
            Panel_InKetQua.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6;
        }

        private void Button_GoogleMap_MouseEnter(object sender, EventArgs e)
        {
            Panel_GoogleMap.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6_hover;
        }

        private void Button_GoogleMap_MouseLeave(object sender, EventArgs e)
        {
            Panel_GoogleMap.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.staticbutton6;
        }

        private void PB_QuayLai_Click(object sender, EventArgs e)
        {
            Panel_TimKiem_Click(sender, e);
        }

        private void ShowPopup(Panel popup)
        {
            int step = 3;
            Size old = popup.Size;
            popup.Size = new Size(old.Width, 0);

            while (popup.Size.Height < old.Height)
            {
                popup.Size = new Size(old.Width, popup.Size.Height + step);
                popup.Refresh();
            }

            popup.Size = old;
        }

        private void HidePopup(Panel popup)
        {
            int step = 3;
            Size old = popup.Size;

            while (popup.Size.Height > 0)
            {
                popup.Size = new Size(old.Width, popup.Size.Height - step);
                popup.Refresh();
            }

            popup.Size = old;
        }

        private void AddItems(Panel popup, List<string> items)
        {
            Font myFont = new Font("Calibri", 9, FontStyle.Bold);
            String plaintext = "";
            List<Label> myLabels = new List<Label>();
            Point hook = new Point(popup.Location.X + popup.Width, popup.Location.Y);
            Point curLocation = new Point();

            for (int i = 0; i < items.Count; i++)
            {
                plaintext += items[i] + "\n\n";

                Label myLabel = new Label();

                myLabel.Text = items[i];
                myLabel.Visible = true;
                myLabel.Font = myFont;
            }

            popup.Size = TextRenderer.MeasureText(plaintext, myFont);
            popup.Location = new Point(hook.X - popup.Width, hook.Y);

            foreach (Label myLabel in myLabels)
            {
                myLabel.Location = curLocation;
                popup.Controls.Add(myLabel);

                curLocation = new Point(curLocation.X + popup.Size.Height / myLabels.Count, curLocation.Y);
            }
        }

        private void PB_Arrow_Click(object sender, EventArgs e)
        {
            if (arrow_down)
            {
                PB_Arrow.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.arrow_up;
                arrow_down = false;

                List<string> items = new List<string>();

                items.Add("Tìm kiếm theo hướng khác 1 abcdefghi");
                items.Add("Tìm kiếm theo hướng khác 2 abc");
                items.Add("Tìm kiếm theo hướng khác 3 a");
                items.Add("Tìm kiếm theo hướng khác 4 abcdefghijklmn");

                AddItems(Panel_Popup_HuongTimKhac, items);
                Panel_Popup_HuongTimKhac.Visible = true;
                ShowPopup(Panel_Popup_HuongTimKhac);
            }
            else
            {
                PB_Arrow.BackgroundImage = QLQTPM_Nhom03.Properties.Resources.arrow_down;
                arrow_down = true;

                HidePopup(Panel_Popup_HuongTimKhac);
                Panel_Popup_HuongTimKhac.Visible = false;
            }
        }
    }
}
